<?php

declare(strict_types=1);

namespace app\model\mini;

use app\model\admin\Product;
use app\model\admin\ProductAttrValue;
use app\model\AdminBaseModel;
use app\model\member\MpConfig;

/**
 * @mixin \think\Model
 */
class Order extends MiniBaseModel
{
    // 数据表名称
    protected $table = 'user_order';
    protected $scopeField = true;

    // 可搜索字段
    protected $searchField = [];
    protected $singleSearchField = [];
    // 可作为条件的字段
    protected $whereField = ['order_sn', 'user_id'];
    // 可做为时间范围查询的字段
    protected $timeField = ['created_at', 'pay_at'];
    // 不允许删除的ID
    public $noDeletionId = [];
    public function orderItem()
    {
        return $this->hasMany(OrderItem::class, 'order_id', 'id');
    }
    // public function refund()
    // {
    //     return $this->(OrderItem::class, 'order_id', 'id');
    // }
    public function address()
    {
        return $this->hasMany(Address::class, 'address_id', 'id');
    }
    public function getPayAtAttr($value, $data)
    {
        if (isset($data['pay_at']) && $data['pay_at']) {
            return date("Y-m-d H:i:s", (int)$value);
        }
    }
    public function getSendTimeAttr($value, $data)
    {
        if (isset($data['send_time']) && $data['send_time']) {
            return date("Y-m-d H:i:s", (int)$value);
        }
    }
}
